package thired.class01_sort;

public class Class01_Bubblesort {
    public static void bubbleSort(int[] nums){
        if(nums == null || nums.length < 2 ){
            return;
        }
        for (int i = nums.length - 1; i >= 0; i--) {
            for (int j = 0; j < i; j++) {
                if(nums[j] > nums[j + 1]){
                    swap(nums,j,j + 1);
                }
            }
        }
    }
    public static void swap(int[] nums,int i ,int j){
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }

    public static void main(String[] args) {
        int[] arr = new int[]{8,7,5,2,6,4,3,1,9};
        bubbleSort(arr);
        for (int i : arr) {
            System.out.print(i);
        }
    }
}
